<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    let user = {
      name: "小灰",
      year: "2020",
    };
    // 打印对象所有的属性名
    console.log(Object.keys(user));
    // 打印对象所有的属性值
    console.log(Object.values(user));
    // 打印属性名和属性值并转化为一个二维数组
    console.log(JSON.stringify(Object.entries(user), null, 2));

    // 遍历属性名
    for (const key in user) {
      console.log(key);
    }
    // 遍历属性值
    for (const key in user) {
      console.log(user[key]);
    }

    // for-of遍历数组对象
    let arr = [{ chinese: 56, english: 99 }];
    for (const iterator of arr) {
      console.log(iterator);
    }
  </script>
</html>
